package com.buss.user.service.impl;
import com.buss.user.service.BnsUserFriendServiceI;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.system.service.SystemService;

import com.buss.user.entity.BnsUserFriendEntity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.io.Serializable;

@Service("bnsUserFriendService")
@Transactional
public class BnsUserFriendServiceImpl extends CommonServiceImpl implements BnsUserFriendServiceI {

	@Autowired
	private SystemService systemService;
	
 	public <T> void delete(T entity) {
 		super.delete(entity);
 		//执行删除操作配置的sql增强
		this.doDelSql((BnsUserFriendEntity)entity);
 	}
 	
 	public <T> Serializable save(T entity) {
 		Serializable t = super.save(entity);
 		//执行新增操作配置的sql增强
 		this.doAddSql((BnsUserFriendEntity)entity);
 		return t;
 	}
 	
 	public <T> void saveOrUpdate(T entity) {
 		super.saveOrUpdate(entity);
 		//执行更新操作配置的sql增强
 		this.doUpdateSql((BnsUserFriendEntity)entity);
 	}
 	
 	/**
	 * 默认按钮-sql增强-新增操作
	 * @param id
	 * @return
	 */
 	public boolean doAddSql(BnsUserFriendEntity t){
	 	return true;
 	}
 	/**
	 * 默认按钮-sql增强-更新操作
	 * @param id
	 * @return
	 */
 	public boolean doUpdateSql(BnsUserFriendEntity t){
	 	return true;
 	}
 	/**
	 * 默认按钮-sql增强-删除操作
	 * @param id
	 * @return
	 */
 	public boolean doDelSql(BnsUserFriendEntity t){
	 	return true;
 	}
 	
 	/**
	 * 替换sql中的变量
	 * @param sql
	 * @return
	 */
 	public String replaceVal(String sql,BnsUserFriendEntity t){
 		sql  = sql.replace("#{id}",String.valueOf(t.getId()));
 		sql  = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
 		sql  = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
 		sql  = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
 		sql  = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
 		sql  = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
 		sql  = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
 		sql  = sql.replace("#{user_id}",String.valueOf(t.getUserId()));
 		sql  = sql.replace("#{friend_id}",String.valueOf(t.getFriendId()));
 		sql  = sql.replace("#{is_gre}",String.valueOf(t.getIsGre()));
 		sql  = sql.replace("#{fz}",String.valueOf(t.getFz()));
 		sql  = sql.replace("#{fy}",String.valueOf(t.getFy()));
 		sql  = sql.replace("#{UUID}",UUID.randomUUID().toString());
 		return sql;
 	}
 	
 	/**
 	 * 添加条件查询好友
 	 * @param map
 	 * @return
 	 */
 	public List<Map<String, Object>>  searchFriendLists(Map<String,String> map){
 		String sql ="SELECT w.friend_id,a.user_id,a.user_name,a.headerimg,a.signature,a.age "
				+ "from bns_user_friend w LEFT JOIN bns_users_info a on w.friend_id = a.user_id where  1 = 1";
		
 		if(StringUtil.isNotEmpty(map.get("userId"))){
 			sql += " and a.user_id ='"+ map.get("userId")+ "' ";
 		}
		if(StringUtil.isNotEmpty(map.get("sex"))){
			sql += " and a.gender ='"+ map.get("sex")+ "' ";
		}
		if(StringUtil.isNotEmpty(map.get("headerimg"))){
			sql += " and a.headerimg != NULL ";
		}
		if(StringUtil.isNotEmpty(map.get("age1"))){
			sql += " and a.age >= "+map.get("age1");
		}
		if(StringUtil.isNotEmpty(map.get("age2"))){
			sql += " and a.age <= "+map.get("age2");
		}
		if(StringUtil.isNotEmpty(map.get("userName"))){
			sql += " and a.user_name=' "+map.get("userName")+"'"; 
		}
		if(StringUtil.isNotEmpty(map.get("abode"))){	//居住地
			sql += " and a.abode=' "+map.get("abode")+"'"; 
		}
		if(StringUtil.isNotEmpty(map.get("address"))){	//出生地
			sql += " and a.address=' "+map.get("address")+"'"; 
		}
		if(StringUtil.isNotEmpty(map.get("birthday"))){	//出生地
			sql += " and a.birthday=' "+map.get("birthday")+"'"; 
		}
		
		List<Map<String, Object>> lists = systemService.findForJdbc(sql, 1, 100);
		return lists;
 	}
 	
 	
 	
 	
 	
 	
 	
}